home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 127 / PC Guia 127.iso / Software / Produtividade / OpenOffice.org 2.0.1 / openofficeorg3.cab / master_refs_workaround.xsl < prev    next >
Extensible Markup Language  |  2005-09-10  |  30KB  |  680 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3.  
  4.     OpenOffice.org - a multi-platform office productivity suite
  5.  
  6.     $RCSfile: master_refs_workaround.xsl,v $
  7.  
  8.     $Revision: 1.7 $
  9.  
  10.     last change: $Author: rt $ $Date: 2005/09/08 22:09:21 $
  11.  
  12.     The Contents of this file are made available subject to
  13.     the terms of GNU Lesser General Public License Version 2.1.
  14.  
  15.  
  16.       GNU Lesser General Public License Version 2.1
  17.       =============================================
  18.       Copyright 2005 by Sun Microsystems, Inc.
  19.       901 San Antonio Road, Palo Alto, CA 94303, USA
  20.  
  21.       This library is free software; you can redistribute it and/or
  22.       modify it under the terms of the GNU Lesser General Public
  23.       License version 2.1, as published by the Free Software Foundation.
  24.  
  25.       This library is distributed in the hope that it will be useful,
  26.       but WITHOUT ANY WARRANTY; without even the implied warranty of
  27.       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  28.       Lesser General Public License for more details.
  29.  
  30.       You should have received a copy of the GNU Lesser General Public
  31.       License along with this library; if not, write to the Free Software
  32.       Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  33.       MA  02111-1307  USA
  34.  
  35. -->
  36. <!--
  37.     For further documentation and updates visit http://xml.openoffice.org/sx2ml
  38. -->
  39. <xsl:stylesheet
  40.         xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  41.         xmlns:office="http://openoffice.org/2000/office"
  42.         xmlns:style="http://openoffice.org/2000/style"
  43.         xmlns:text="http://openoffice.org/2000/text"
  44.         xmlns:table="http://openoffice.org/2000/table"
  45.         xmlns:draw="http://openoffice.org/2000/drawing"
  46.         xmlns:fo="http://www.w3.org/1999/XSL/Format"
  47.         xmlns:xlink="http://www.w3.org/1999/xlink"
  48.         xmlns:number="http://openoffice.org/2000/datastyle"
  49.         xmlns:svg="http://www.w3.org/2000/svg"
  50.         xmlns:chart="http://openoffice.org/2000/chart"
  51.         xmlns:dr3d="http://openoffice.org/2000/dr3d"
  52.         xmlns:math="http://www.w3.org/1998/Math/MathML"
  53.         xmlns:form="http://openoffice.org/2000/form"
  54.         xmlns:script="http://openoffice.org/2000/script"
  55.         xmlns:dc="http://purl.org/dc/elements/1.1/"
  56.         xmlns:meta="http://openoffice.org/2000/meta"
  57.         xmlns:config="http://openoffice.org/2001/config"
  58.         xmlns:help="http://openoffice.org/2000/help"
  59.         xmlns:java="http://xml.apache.org/xslt/java"
  60.         xmlns:sxg="http://www.jclark.com/xt/java/org.openoffice.xslt.OOoMasterDocument"
  61.         xmlns:xt="http://www.jclark.com/xt"
  62.         xmlns:common="http://exslt.org/common"
  63.         xmlns:xalan="http://xml.apache.org/xalan"
  64.         xmlns="http://www.w3.org/1999/xhtml"
  65.         version="1.0"
  66.         exclude-result-prefixes="office style text table draw fo xlink number svg chart dr3d math form script dc meta config help java sxg xt common xalan">
  67.  
  68.  
  69.     <!--
  70.     SUMMARY:
  71.      following parameter triggers a (quite time consuming) workaround for enabling of chapter links in the table-of-content.
  72.  
  73.     IN DETAIL:
  74.      Currently some links used in the Office XML (for example, in the content table as '#7.Some%20Example%20Headline%7Outline')
  75.      are not a valid URLs (cp. bug id# 102311).
  76.      No file destination is specified nor exist any anchor element for these links in the Office XML.
  77.      A workaround for this transformation therefore had to be made. This time-consuming mechanism is disabled by default and
  78.      can be activated by a parameter (i.e. 'childDocumentExist'). A creation of an anchor is made for each header element.
  79.      All header titles gonna be encoded to be usable in a relative URL.  -->
  80.  
  81.  
  82.     <!--
  83.         CREATION OF A HELPER VARIABLE AS WORKAROUND FOR THE CONTENT TABLE ULR BUG
  84.  
  85.  
  86.         As no valid URL from the content table to the child documents exist in the content table,
  87.         a work-around is done:
  88.  
  89.         First two helper variables are being created.
  90.  
  91.         One containing the list of all references of the master document:
  92.         containg all their title,
  93.         for example:
  94.  
  95.             <chapter-ref title="aTitle 1" />
  96.             <chapter-ref title="aTitle 2" />
  97.             <chapter-ref title="aTitle 2/>
  98.             <chapter-ref title="aTitle 3/>
  99.  
  100.         The other containing all heading from the child documents linked from the master document.
  101.         The variable 'childrenHeadings' contains their title and the number of preceding similar titles,
  102.         for example:
  103.  
  104.  
  105.             <child file-url="aURL">
  106.                 <heading title="aTitle1" level="1">
  107.                 <heading title="aTitle2" level="2">
  108.                 <heading title="aTitle3" level="1">
  109.             </child>
  110.  
  111.         For each chapter reference from the content table the
  112.  
  113.          by encoding the chapter names of the child document with the java URLEncoder and
  114.         use this as a part of a link. Furthermore for all heading elements a encoded anchor will be created from the heading.
  115.         Last the workaround parses all children documents for this anhor, as there is no distinction of files from the content table entries.
  116.  
  117.         The new added node set to the globalData variable concering the content table is written as
  118.  
  119.  
  120.         <content-table-headings>
  121.             <heading file-url="aFileURLToTheGeneratedHeading1" level="1">
  122.             <heading file-url="aFileURLToTheGeneratedHeading2" level="2">
  123.             <heading file-url="aFileURLToTheGeneratedHeading1" level="1">
  124.             <heading file-url="aFileURLToTheGeneratedHeading2" level="2">
  125.         </content-table-headings>
  126.  
  127.  
  128.         Preconditions:
  129.         The correct sequence of child documents according to the Content Table is necessary, granted by the office.
  130.     -->
  131.     <xsl:template name="create-helper-variables-for-Content-Table">
  132.         <xsl:param name="globalData" />
  133.  
  134.         <xsl:if test="$debugEnabled">
  135.             <xsl:message>Creation of master document helper variable for the content table....</xsl:message>
  136.         </xsl:if>
  137.         <!-- Here a helper variable for the content table is created, containing
  138.              all chapter-references which point to a child document.
  139.              In the variable, a 'chapter-ref' element will be created,
  140.              containg the title, stripped from surrounding spaces,
  141.              and the reference, for example:
  142.  
  143.                 <chapter-ref
  144.                     title="sample-Title 1"
  145.                     content-table-id="../dummy.sxw" />
  146.                 <chapter-ref title="a-Title 2" />
  147.                 <chapter-ref title="cTitle 1" />
  148.                 <chapter-ref title="aTitle 3" />
  149.             -->
  150.         <xsl:variable name="chapterRefs-RTF">
  151.             <!-- XPATH starting with '/*/' as the flat and the zipped XML file format have different root elements -->
  152.             <xsl:for-each select="/*/office:body/text:table-of-content/text:index-body/text:p/text:a">
  153.                 <xsl:element name="chapter-ref" namespace="">
  154.                     <xsl:variable name="title"><xsl:apply-templates mode="concatenate" /></xsl:variable>
  155.                     <xsl:attribute name="title">
  156.                         <xsl:value-of select="normalize-space(string($title))" />
  157.                     </xsl:attribute>
  158.                     <xsl:attribute name="content-table-id">
  159.                         <xsl:value-of select="@xlink:href" />
  160.                     </xsl:attribute>
  161.                 </xsl:element>
  162.             </xsl:for-each>
  163.         </xsl:variable>
  164.  
  165.         <xsl:if test="$debugEnabled">
  166.             <xsl:message>Finished the Creation of master document helper variable for the content table!</xsl:message>
  167.             <xsl:message>Creation of master document helper variable for the child documents...</xsl:message>
  168.         </xsl:if>
  169.         <!-- Here a helper variable of created from the children documents.
  170.              Containg all heading elements from the child documents. Some or all of them are
  171.              chapters referenced by the Global Document.
  172.              The variable contains their title, the level of the heading and the file URL of the child,
  173.              for example:
  174.  
  175.                 <heading title="aTitle1" level="1" file-url="aURL1">
  176.                 <heading title="aTitle2" level="2" file-url="aURL1">
  177.                 <heading title="aTitle3" level="1" file-url="aURL1">
  178.                 <heading title="aTitle4" level="1" file-url="aURL2">
  179.                 <heading title="aTitle5" level="2" file-url="aURL2">
  180.                 <heading title="aTitle2" level="3" file-url="aURL2">
  181.                 <heading title="aTitle6" level="3" file-url="aURL2">
  182.                 <heading-count>7</heading-count>
  183.             -->
  184.         <!-- all headers from children documents will be added -->
  185.         <xsl:variable name="childrenHeadings-RTF">
  186.             <xsl:apply-templates select="/*/office:body/text:section" mode="creation-of-variable" />
  187.         </xsl:variable>
  188.         <xsl:if test="$debugEnabled">
  189.             <xsl:message>Finished the Creation of master document helper variable for the child documents!</xsl:message>
  190.         </xsl:if>
  191.         <xsl:choose>
  192.             <xsl:when test="function-available('xalan:nodeset')">
  193.                 <xsl:call-template name="create-global-variable-for-Content-Table">
  194.                     <xsl:with-param name="chapterRefs" select="xalan:nodeset($chapterRefs-RTF)" />
  195.                     <xsl:with-param name="childrenHeadings" select="xalan:nodeset($childrenHeadings-RTF)" />
  196.                     <xsl:with-param name="globalData" select="$globalData" />
  197.                 </xsl:call-template>
  198.             </xsl:when>
  199.             <xsl:when test="function-available('common:node-set')">
  200.                 <xsl:call-template name="create-global-variable-for-Content-Table">
  201.                     <xsl:with-param name="chapterRefs" select="common:node-set($chapterRefs-RTF)" />
  202.                     <xsl:with-param name="childrenHeadings" select="common:node-set($childrenHeadings-RTF)" />
  203.                     <xsl:with-param name="globalData" select="$globalData" />
  204.                 </xsl:call-template>
  205.             </xsl:when>
  206.             <xsl:when test="function-available('xt:node-set')">
  207.                 <xsl:call-template name="create-global-variable-for-Content-Table">
  208.                     <xsl:with-param name="chapterRefs" select="xt:node-set($chapterRefs-RTF)" />
  209.                     <xsl:with-param name="childrenHeadings" select="xt:node-set($childrenHeadings-RTF)" />
  210.                     <xsl:with-param name="globalData" select="$globalData" />
  211.                 </xsl:call-template>
  212.             </xsl:when>
  213.             <xsl:otherwise>
  214.                 <xsl:message terminate="yes">ERROR: Functions for node-set conversion not found!</xsl:message>
  215.             </xsl:otherwise>
  216.         </xsl:choose>
  217.     </xsl:template>
  218.  
  219.  
  220.     <xsl:template name="create-global-variable-for-Content-Table">
  221.         <xsl:param name="chapterRefs" />
  222.         <xsl:param name="childrenHeadings" />
  223.         <xsl:param name="globalData" />
  224.  
  225.         <xsl:if test="$debugEnabled">
  226.             <!-- helper variable collecting all headings from the master document file children-->
  227.             <xsl:for-each select="$childrenHeadings/heading">
  228.                 <xsl:message>#              <xsl:value-of select="position()" />
  229.                 </xsl:message>
  230.                 <xsl:message>level:         <xsl:value-of select="@level" />
  231.                 </xsl:message>
  232.                 <xsl:message>title:         <xsl:value-of select="@title" />
  233.                 </xsl:message>
  234.                 <xsl:message>encoded-title: <xsl:value-of select="@encoded-title" />
  235.                 </xsl:message>
  236.                 <xsl:message>file-url:      <xsl:value-of select="@file-url" />
  237.                 </xsl:message>
  238.                 <xsl:message>header-no:     <xsl:value-of select="@header-no" />
  239.                 </xsl:message>
  240.                 <xsl:message>**</xsl:message>
  241.             </xsl:for-each>
  242.             <!-- helper variable collecting all heading references from the content table of the the master document -->
  243.             <xsl:message>+-+-+ childrenHeadings/heading-count: <xsl:value-of select="$childrenHeadings/heading-count" />
  244.             </xsl:message>
  245.             <xsl:for-each select="$chapterRefs/chapter-ref">
  246.                 <xsl:message># <xsl:value-of select="position()" />
  247.                 </xsl:message>
  248.                 <xsl:message>title: <xsl:value-of select="@title" />
  249.                 </xsl:message>
  250.                 <xsl:message>**</xsl:message>
  251.             </xsl:for-each>
  252.         </xsl:if>
  253.  
  254.         <xsl:choose>
  255.             <xsl:when test="function-available('sxg:set-heading-no')">
  256.                 <xsl:value-of select="sxg:set-heading-no(1)" />
  257.                 <xsl:value-of select="sxg:set-current-child-no(1)" />
  258.                 <xsl:value-of select="sxg:set-current-child-url(string($childrenHeadings/heading/@file-url))" />
  259.             </xsl:when>
  260.             <xsl:when test="function-available('java:org.openoffice.xslt.OOoMasterDocument.setHeadingNo')">
  261.                 <xsl:value-of select="java:org.openoffice.xslt.OOoMasterDocument.setHeadingNo(1)" />
  262.                 <xsl:value-of select="java:org.openoffice.xslt.OOoMasterDocument.setCurrentChildNo(1)" />
  263.                 <xsl:value-of select="java:org.openoffice.xslt.OOoMasterDocument.setCurrentChildUrl(string($childrenHeadings/heading/@file-ur))" />
  264.             </xsl:when>
  265.         </xsl:choose>
  266.  
  267.         <xsl:if test="$debugEnabled">
  268.             <xsl:message>Creating master document variable for chapter relations....</xsl:message>
  269.         </xsl:if>
  270.         <xsl:variable name="contentTableHeadingsGlobalData-RTF">
  271.             <xsl:element name="content-table-headings" namespace="">
  272.  
  273.                 <!-- had to use a for loop, as a recursion ends with an stackoverflow exception after about 600 recursive calls -->
  274.                 <xsl:choose>
  275.                     <xsl:when test="function-available('sxg:get-heading-no')">
  276.                         <xsl:for-each select="$chapterRefs/chapter-ref">
  277.                             <xsl:call-template name="searchHeadingInChildDocument">
  278.                                 <xsl:with-param name="chapterRefs" select="$chapterRefs" />
  279.                                 <xsl:with-param name="childrenHeadings" select="$childrenHeadings" />
  280.                                 <xsl:with-param name="currentChapterRefNo" select="position()" />
  281.                                 <xsl:with-param name="currentHeadingNo" select="sxg:get-heading-no()" />
  282.                                 <xsl:with-param name="currentChildURL" select="sxg:get-current-child-url()" />
  283.                                 <xsl:with-param name="currentChildNo" select="sxg:get-current-child-no()" />
  284.                             </xsl:call-template>
  285.                         </xsl:for-each>
  286.                     </xsl:when>
  287.                     <xsl:when test="function-available('java:org.openoffice.xslt.OOoMasterDocument.getHeadingNo')">
  288.                         <xsl:for-each select="$chapterRefs/chapter-ref">
  289.                             <xsl:call-template name="searchHeadingInChildDocument">
  290.                                 <xsl:with-param name="chapterRefs" select="$chapterRefs" />
  291.                                 <xsl:with-param name="childrenHeadings" select="$childrenHeadings" />
  292.                                 <xsl:with-param name="currentChapterRefNo" select="position()" />
  293.                                 <xsl:with-param name="currentHeadingNo" select="java:org.openoffice.xslt.OOoMasterDocument.getHeadingNo()" />
  294.                                 <xsl:with-param name="currentChildURL" select="java:org.openoffice.xslt.OOoMasterDocument.getCurrentChildUrl()" />
  295.                                 <xsl:with-param name="currentChildNo" select="java:org.openoffice.xslt.OOoMasterDocument.getCurrentChildNo()" />
  296.                             </xsl:call-template>
  297.                         </xsl:for-each>
  298.                     </xsl:when>
  299.                     <xsl:otherwise>
  300.                         <xsl:message terminate="yes">ERROR: Function not found: java:org.openoffice.xslt.OOoMasterDocument.getHeadingNo()</xsl:message>
  301.                     </xsl:otherwise>
  302.                 </xsl:choose>
  303.             </xsl:element>
  304.  
  305.             <!-- adding the already exisiting global data environment -->
  306.             <xsl:copy-of select="$globalData" />
  307.         </xsl:variable>
  308.         <xsl:if test="$debugEnabled">
  309.             <xsl:message>Finished master document variable for chapter relations!</xsl:message>
  310.         </xsl:if>
  311.  
  312.         <xsl:choose>
  313.             <xsl:when test="function-available('xalan:nodeset')">
  314.                 <xsl:call-template name="start-self-and-children-transformation">
  315.                     <xsl:with-param name="globalData" select="xalan:nodeset($contentTableHeadingsGlobalData-RTF)" />
  316.                 </xsl:call-template>
  317.             </xsl:when>
  318.             <xsl:when test="function-available('xt:node-set')">
  319.                 <xsl:call-template name="start-self-and-children-transformation">
  320.                     <xsl:with-param name="globalData" select="xt:node-set($contentTableHeadingsGlobalData-RTF)" />
  321.                 </xsl:call-template>
  322.             </xsl:when>
  323.             <xsl:when test="function-available('common:node-set')">
  324.                 <xsl:call-template name="start-self-and-children-transformation">
  325.                     <xsl:with-param name="globalData" select="common:node-set($contentTableHeadingsGlobalData-RTF)" />
  326.                 </xsl:call-template>
  327.             </xsl:when>
  328.             <xsl:otherwise>
  329.                 <xsl:message terminate="yes">ERROR: Function not found: java:org.openoffice.xslt.OOoMasterDocument.getOutputURLForHTML</xsl:message>
  330.             </xsl:otherwise>
  331.         </xsl:choose>
  332.     </xsl:template>
  333.  
  334.  
  335.     <xsl:template name="searchHeadingInChildDocument">
  336.         <xsl:param name="chapterRefs" />
  337.         <xsl:param name="childrenHeadings" />
  338.         <xsl:param name="currentChapterRefNo" />
  339.         <xsl:param name="currentHeadingNo" />
  340.         <xsl:param name="currentChildURL" />
  341.         <xsl:param name="currentChildNo" />
  342.         <xsl:variable name="currentChapterRef" select="$chapterRefs/chapter-ref[$currentChapterRefNo]" />
  343.         <xsl:variable name="currentChapterID" select="$currentChapterRef/@content-table-id" />
  344.         <xsl:variable name="currentChapterTitle" select="$currentChapterRef/@title" />
  345.         <xsl:variable name="currentChildHeading" select="$childrenHeadings/heading[$currentHeadingNo]" />
  346.         <xsl:variable name="headingTitle" select="$currentChildHeading/@title" />
  347.         <xsl:variable name="headingLevel" select="$currentChildHeading/@level" />
  348.         <xsl:variable name="headingNo" select="$currentChildHeading/@header-no" />
  349.         <xsl:variable name="newChildURL" select="string($currentChildHeading/@file-url)" />
  350.  
  351.         <xsl:if test="$debugEnabled">
  352.             <xsl:message>*** new heading </xsl:message>
  353.             <xsl:message>currentChapterID:    <xsl:value-of select="$currentChapterID" />
  354.             </xsl:message>
  355.             <xsl:message>currentChapterTitle: <xsl:value-of select="$currentChapterTitle" />
  356.             </xsl:message>
  357.             <xsl:message>currentChapterID:    <xsl:value-of select="$currentChapterID" />
  358.             </xsl:message>
  359.             <xsl:message>currentHeadingNo:    <xsl:value-of select="$currentHeadingNo" />
  360.             </xsl:message>
  361.             <xsl:message>headingTitle:        <xsl:value-of select="$headingTitle" />
  362.             </xsl:message>
  363.             <xsl:message>headingLevel:        <xsl:value-of select="$headingLevel" />
  364.             </xsl:message>
  365.             <xsl:message>headingNo:           <xsl:value-of select="$headingNo" />
  366.             </xsl:message>
  367.             <xsl:message>newChildURL:         <xsl:value-of select="$newChildURL" />
  368.             </xsl:message>
  369.         </xsl:if>
  370.  
  371.         <xsl:variable name="isNewFile" select="string($newChildURL) != string($currentChildURL)" />
  372.         <xsl:if test="$isNewFile">
  373.             <!-- reset of the already collected child headers -->
  374.             <xsl:call-template name="calc-chapter-numbers">
  375.                 <xsl:with-param name="level" select="0" />
  376.             </xsl:call-template>
  377.         </xsl:if>
  378.         <xsl:variable name="absoluteChapterLevel">
  379.             <xsl:call-template name="calc-chapter-numbers">
  380.                 <xsl:with-param name="level" select="number($headingLevel)" />
  381.             </xsl:call-template>
  382.         </xsl:variable>
  383.  
  384.         <xsl:variable name="isChapterHeading" select="$headingTitle = $currentChapterTitle" />
  385.  
  386.         <xsl:variable name="outFileURL">
  387.             <xsl:choose>
  388.                 <xsl:when test="function-available('sxg:get-output-u-r-l-for-h-t-m-l')">
  389.                     <xsl:value-of select="sxg:get-output-u-r-l-for-h-t-m-l($newChildURL)" />
  390.                 </xsl:when>
  391.                 <xsl:when test="function-available('java:org.openoffice.xslt.OOoMasterDocument.getOutputURLForHTML')">
  392.                     <xsl:value-of select="java:org.openoffice.xslt.OOoMasterDocument.getOutputURLForHTML($newChildURL)" />
  393.                 </xsl:when>
  394.                 <xsl:otherwise>
  395.                     <xsl:message terminate="yes">ERROR: Function not found: java:org.openoffice.xslt.OOoMasterDocument.getOutputURLForHTML</xsl:message>
  396.                 </xsl:otherwise>
  397.             </xsl:choose>
  398.         </xsl:variable>
  399.  
  400.         <xsl:element name="heading" namespace="">
  401.             <!-- necessary to as ID from the content table to get the correct heading element (the buggy URL used as ID)-->
  402.             <xsl:attribute name="content-table-id">
  403.                 <xsl:choose>
  404.                     <xsl:when test="$isChapterHeading">
  405.                         <xsl:value-of select="$currentChapterID" />
  406.                     </xsl:when>
  407.                     <xsl:otherwise>
  408.                         <xsl:text>only a heading, but not a chapter</xsl:text>
  409.                     </xsl:otherwise>
  410.                 </xsl:choose>
  411.             </xsl:attribute>
  412.             <!-- no of the used child, necessary for quick finding of chapters of next file  -->
  413.             <xsl:attribute name="child-document-no">
  414.                 <xsl:choose>
  415.                     <xsl:when test="$isNewFile">
  416.                         <xsl:value-of select="$currentChildNo + 1" />
  417.                     </xsl:when>
  418.                     <xsl:otherwise>
  419.                         <xsl:value-of select="$currentChildNo" />
  420.                     </xsl:otherwise>
  421.                 </xsl:choose>
  422.             </xsl:attribute>
  423.             <!-- the URL of the child document source, containing the heading -->
  424.             <xsl:attribute name="file-url">
  425.                 <xsl:value-of select="$newChildURL" />
  426.             </xsl:attribute>
  427.             <xsl:attribute name="out-file-url">
  428.                 <xsl:value-of select="$outFileURL" />
  429.             </xsl:attribute>
  430.             <xsl:attribute name="level">
  431.                 <xsl:value-of select="$headingLevel" />
  432.             </xsl:attribute>
  433.             <xsl:attribute name="title">
  434.                 <xsl:value-of select="$headingTitle" />
  435.             </xsl:attribute>
  436.             <xsl:attribute name="encoded-title">
  437.                 <xsl:value-of select="$currentChildHeading/@encoded-title" />
  438.             </xsl:attribute>
  439.             <xsl:attribute name="absolute-chapter-level">
  440.                 <xsl:value-of select="$absoluteChapterLevel" />
  441.             </xsl:attribute>
  442.         </xsl:element>
  443.  
  444.  
  445.         <xsl:choose>
  446.             <xsl:when test="$childrenHeadings/heading-count != $currentHeadingNo">
  447.                 <!-- procede as long the list of children isn'nt worked through -->
  448.                 <xsl:choose>
  449.                     <xsl:when test="$isChapterHeading">
  450.                         <!-- global variables have to be set, so the for-each loop can access them -->
  451.                         <xsl:choose>
  452.                             <xsl:when test="function-available('sxg:set-heading-no')">
  453.                                 <xsl:value-of select="sxg:set-heading-no($currentHeadingNo + 1)" />
  454.                                 <xsl:if test="$isNewFile">
  455.                                     <xsl:value-of select="sxg:set-current-child-no($currentChildNo + 1)" />
  456.                                     <xsl:value-of select="sxg:set-current-child-url(string($newChildURL))" />
  457.                                 </xsl:if>
  458.                             </xsl:when>
  459.                             <xsl:when test="function-available('java:org.openoffice.xslt.OOoMasterDocument.setHeadingNo')">
  460.                                 <xsl:value-of select="java:org.openoffice.xslt.OOoMasterDocument.setHeadingNo($currentHeadingNo + 1)" />
  461.                                 <xsl:if test="$isNewFile">
  462.                                     <xsl:value-of select="java:org.openoffice.xslt.OOoMasterDocument.setCurrentChildNo($currentChildNo + 1)" />
  463.                                     <xsl:value-of select="java:org.openoffice.xslt.OOoMasterDocument.setCurrentChildUrl($newChildURL)" />
  464.                                 </xsl:if>
  465.                             </xsl:when>
  466.                             <xsl:otherwise>
  467.                                 <xsl:message terminate="yes">ERROR: Function not found: java:org.openoffice.xslt.OOoMasterDocument.setHeadingNo</xsl:message>
  468.                             </xsl:otherwise>
  469.                         </xsl:choose>
  470.                     </xsl:when>
  471.                     <xsl:otherwise>
  472.                         <!-- not a chapter heading, call itself until a chapter ref is found or the end of headings is reached -->
  473.                         <xsl:call-template name="searchHeadingInChildDocument">
  474.                             <xsl:with-param name="chapterRefs" select="$chapterRefs" />
  475.                             <xsl:with-param name="childrenHeadings" select="$childrenHeadings" />
  476.                             <xsl:with-param name="currentChapterRefNo" select="$currentChapterRefNo" />
  477.                             <xsl:with-param name="currentHeadingNo" select="$currentHeadingNo + 1" />
  478.                             <xsl:with-param name="currentChildURL" select="$currentChildURL" />
  479.                             <xsl:with-param name="currentChildNo" select="$currentChildNo" />
  480.                         </xsl:call-template>
  481.                     </xsl:otherwise>
  482.                 </xsl:choose>
  483.             </xsl:when>
  484.             <xsl:otherwise>
  485.                 <xsl:if test="$debugEnabled">
  486.                     <xsl:message>All child documents have been walked through without finding the chapter name!</xsl:message>
  487.                     <xsl:message>       childrenHeadings/heading-count:    <xsl:value-of select="$childrenHeadings/heading-count" />
  488.                     </xsl:message>
  489.                     <xsl:message>       currentHeadingNo:                  <xsl:value-of select="$currentHeadingNo" />
  490.                     </xsl:message>
  491.                 </xsl:if>
  492.             </xsl:otherwise>
  493.         </xsl:choose>
  494.     </xsl:template>
  495.  
  496.  
  497.     <!-- To make the headings unique, the absolute heading is added to them
  498.          E.g. The level 1.2.3.4. would result into a 1_2_3_4 string -->
  499.     <xsl:template name="calc-chapter-numbers">
  500.         <xsl:param name="level" />
  501.  
  502.         <xsl:choose>
  503.             <xsl:when test="function-available('sxg:calc-chapter-numbers')">
  504.                 <xsl:value-of select="sxg:calc-chapter-numbers($level)" />
  505.             </xsl:when>
  506.             <xsl:when test="function-available('java:org.openoffice.xslt.OOoMasterDocument.calcChapterNumbers')">
  507.                 <xsl:value-of select="java:org.openoffice.xslt.OOoMasterDocument.calcChapterNumbers($level)" />
  508.             </xsl:when>
  509.             <xsl:otherwise>
  510.                 <xsl:message terminate="yes">ERROR: Function not found: java:org.openoffice.xslt.OOoMasterDocument.calcChapterNumbers</xsl:message>
  511.             </xsl:otherwise>
  512.         </xsl:choose>
  513.     </xsl:template>
  514.  
  515.     <!-- ******************************************************************************* -->
  516.     <!-- ***  Creation of helper variable of the headings of all children documents  *** -->
  517.     <!-- ******************************************************************************* -->
  518.  
  519.  
  520.     <xsl:template match="/*/office:body/text:section" mode="creation-of-variable">
  521.  
  522.         <xsl:call-template name="parseHeadingsFromChildren" />
  523.  
  524.         <!-- after the last child document the master document will be parsed -->
  525.         <xsl:if test="position() = last()">
  526.             <!-- search the master document after all child documents have been searched
  527.  
  528.  
  529.             Office SDK PATCH NO INDEX ELEMENT WANTED !! - null pointer exception
  530.             <xsl:call-template name="getPreviousHeaderNo">
  531.                 <xsl:with-param name="amountOfCurrentHeading"   select="count(following-sibling::text:h)" />
  532.                 <xsl:with-param name="nodeToSearchForHeading"   select="following-sibling::text:h" />
  533.             </xsl:call-template>
  534.                                                                     -->
  535.  
  536.            <!-- get the overall No of Headers -->
  537.             <xsl:call-template name="getAllHeaderNo" />
  538.         </xsl:if>
  539.     </xsl:template>
  540.  
  541.  
  542.     <!-- redirection to have a speakable template name -->
  543.     <xsl:template name="parseHeadingsFromChildren">
  544.         <xsl:variable name="fileRef" select="string(text:section-source/@xlink:href)" />
  545.         <xsl:choose>
  546.             <xsl:when test="function-available('sxg:get-content-u-r-l')">
  547.                 <xsl:call-template name="getContentRootNode">
  548.                     <xsl:with-param name="fileURL" select="sxg:get-content-u-r-l($fileRef)" />
  549.                 </xsl:call-template>
  550.             </xsl:when>
  551.             <xsl:when test="function-available('java:org.openoffice.xslt.OOoMasterDocument.getContentURL')">
  552.                 <xsl:call-template name="getContentRootNode">
  553.                     <xsl:with-param name="fileURL" select="java:org.openoffice.xslt.OOoMasterDocument.getContentURL($fileRef)" />
  554.                 </xsl:call-template>
  555.             </xsl:when>
  556.             <xsl:otherwise>
  557.                 <xsl:message terminate="yes">ERROR: Function not found: java:org.openoffice.xslt.OOoMasterDocument.getContentURL!</xsl:message>
  558.             </xsl:otherwise>
  559.         </xsl:choose>
  560.     </xsl:template>
  561.  
  562.  
  563.     <xsl:template name="getContentRootNode">
  564.         <xsl:param name="fileURL" />
  565.  
  566.         <xsl:variable name="childRootNode" select="document($fileURL)" />
  567.         <xsl:call-template name="getPreviousHeaderNo">
  568.             <xsl:with-param name="fileURL" select="$fileURL" />
  569.             <!-- the absolute source path will be added as prefix -->
  570.             <xsl:with-param name="amountOfCurrentHeading" select="count($childRootNode/*/office:body/descendant::text:h)" />
  571.             <xsl:with-param name="nodeToSearchForHeading" select="$childRootNode/*/office:body/descendant::text:h" />
  572.         </xsl:call-template>
  573.  
  574.     </xsl:template>
  575.  
  576.  
  577.     <xsl:template name="getPreviousHeaderNo">
  578.         <xsl:param name="fileURL" />
  579.         <xsl:param name="nodeToSearchForHeading" />
  580.         <xsl:param name="amountOfCurrentHeading" />
  581.  
  582.         <xsl:choose>
  583.             <xsl:when test="function-available('sxg:get-previous-child-documents-heading-count')">
  584.                 <xsl:call-template name="addHeadingInfo">
  585.                     <xsl:with-param name="nodeToSearchForHeading" select="$nodeToSearchForHeading" />
  586.                     <xsl:with-param name="fileURL" select="$fileURL" />
  587.                     <xsl:with-param name="previousHeader" select="sxg:get-previous-child-documents-heading-count($amountOfCurrentHeading)" />
  588.                 </xsl:call-template>
  589.             </xsl:when>
  590.             <xsl:when test="function-available('java:org.openoffice.xslt.OOoMasterDocument.getPreviousChildDocumentsHeadingCount')">
  591.                 <xsl:call-template name="addHeadingInfo">
  592.                     <xsl:with-param name="nodeToSearchForHeading" select="$nodeToSearchForHeading" />
  593.                     <xsl:with-param name="fileURL" select="$fileURL" />
  594.                     <xsl:with-param name="previousHeader" select="java:org.openoffice.xslt.OOoMasterDocument.getPreviousChildDocumentsHeadingCount($amountOfCurrentHeading)" />
  595.                 </xsl:call-template>
  596.             </xsl:when>
  597.             <xsl:otherwise>
  598.                 <xsl:message terminate="yes">ERROR: Function not found: java:org.openoffice.xslt.OOoMasterDocument.getPreviousChildDocumentsHeadingCount</xsl:message>
  599.             </xsl:otherwise>
  600.         </xsl:choose>
  601.  
  602.     </xsl:template>
  603.  
  604.  
  605.     <xsl:template name="addHeadingInfo">
  606.         <xsl:param name="fileURL" />
  607.         <xsl:param name="previousHeader" />
  608.         <xsl:param name="nodeToSearchForHeading" />
  609.  
  610.         <xsl:variable name="previousHeader2" select="number($previousHeader)" />
  611.         <xsl:for-each select="$nodeToSearchForHeading">
  612.             <xsl:variable name="title"><xsl:apply-templates mode="concatenate" /></xsl:variable>
  613.             <xsl:variable name="encodedTitle">
  614.                 <xsl:call-template name="encode-string">
  615.                     <!-- the space has to be normalized,
  616.                         otherwise an illegal argument exception will be thrown for XT-->
  617.                     <xsl:with-param name="textToBeEncoded" select="normalize-space(string($title))" />
  618.                 </xsl:call-template>
  619.             </xsl:variable>
  620.             <!--
  621.             <xsl:if test="$debugEnabled">
  622.                 <xsl:message>
  623.                     title:<xsl:value-of select="$title" />
  624.                     encoded-title:<xsl:value-of select="$encodedTitle" />
  625.                     level:<xsl:value-of select="@text:level" />
  626.                     file-uRL:<xsl:value-of select="$fileURL" />
  627.                     header-no:<xsl:value-of select="position() + $previousHeader2" />
  628.                 </xsl:message>
  629.             </xsl:if>
  630.             -->
  631.             <xsl:element name="heading" namespace="">
  632.                 <!-- odd but 'descendant:text()' didn't work, but '.', to get all text nodes of the header -->
  633.                 <xsl:attribute name="title">
  634.                     <xsl:value-of select="normalize-space(string($title))" />
  635.                 </xsl:attribute>
  636.                 <xsl:attribute name="encoded-title">
  637.                     <xsl:value-of select="$encodedTitle" />
  638.                 </xsl:attribute>
  639.                 <xsl:attribute name="level">
  640.                     <xsl:value-of select="@text:level" />
  641.                 </xsl:attribute>
  642.                 <xsl:attribute name="file-url">
  643.                     <xsl:value-of select="$fileURL" />
  644.                 </xsl:attribute>
  645.                 <xsl:attribute name="header-no">
  646.                     <xsl:value-of select="position() + $previousHeader2" />
  647.                 </xsl:attribute>
  648.             </xsl:element>
  649.         </xsl:for-each>
  650.     </xsl:template>
  651.  
  652.  
  653.     <xsl:template name="getAllHeaderNo">
  654.         <xsl:choose>
  655.             <xsl:when test="function-available('sxg:get-all-child-documents-heading-count')">
  656.                 <xsl:call-template name="addAllHeaderNoElement">
  657.                     <xsl:with-param name="allHeader" select="sxg:get-all-child-documents-heading-count()" />
  658.                 </xsl:call-template>
  659.             </xsl:when>
  660.             <xsl:when test="function-available('java:org.openoffice.xslt.OOoMasterDocument.getAllChildDocumentsHeadingCount')">
  661.                 <xsl:call-template name="addAllHeaderNoElement">
  662.                     <xsl:with-param name="allHeader" select="java:org.openoffice.xslt.OOoMasterDocument.getAllChildDocumentsHeadingCount()" />
  663.                 </xsl:call-template>
  664.             </xsl:when>
  665.             <xsl:otherwise>
  666.                 <xsl:message terminate="yes">ERROR: Function not found: nodeset</xsl:message>
  667.             </xsl:otherwise>
  668.         </xsl:choose>
  669.     </xsl:template>
  670.  
  671.     <xsl:template name="addAllHeaderNoElement">
  672.         <xsl:param name="allHeader" />
  673.  
  674.         <xsl:element name="heading-count" namespace="">
  675.             <xsl:value-of select="$allHeader" />
  676.         </xsl:element>
  677.     </xsl:template>
  678.  
  679. </xsl:stylesheet>
  680.